package com.ruoyi.shop.idle.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.idle.domain.Idle;
import com.ruoyi.shop.idle.service.IIdleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 闲置物品Controller
 * 
 * @author yjy
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/idle/idle")
public class IdleController extends BaseController
{
    @Autowired
    private IIdleService idleService;

    /**
     * 查询闲置物品列表
     */
    @PreAuthorize("@ss.hasPermi('idle:idle:list')")
    @GetMapping("/list")
    public TableDataInfo list(Idle idle)
    {
        startPage();
        List<Idle> list = idleService.selectIdleList(idle);
        return getDataTable(list);
    }

    /**
     * 导出闲置物品列表
     */
    @PreAuthorize("@ss.hasPermi('idle:idle:export')")
    @Log(title = "闲置物品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Idle idle)
    {
        List<Idle> list = idleService.selectIdleList(idle);
        ExcelUtil<Idle> util = new ExcelUtil<Idle>(Idle.class);
        util.exportExcel(response, list, "闲置物品数据");
    }

    /**
     * 获取闲置物品详细信息
     */
    @PreAuthorize("@ss.hasPermi('idle:idle:query')")
    @GetMapping(value = "/{idleId}")
    public AjaxResult getInfo(@PathVariable("idleId") Long idleId)
    {
        return success(idleService.selectIdleByIdleId(idleId));
    }

    /**
     * 新增闲置物品
     */
    @PreAuthorize("@ss.hasPermi('idle:idle:add')")
    @Log(title = "闲置物品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Idle idle)
    {
        return toAjax(idleService.insertIdle(idle));
    }

    /**
     * 修改闲置物品
     */
    @PreAuthorize("@ss.hasPermi('idle:idle:edit')")
    @Log(title = "闲置物品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Idle idle)
    {
        return toAjax(idleService.updateIdle(idle));
    }

    /**
     * 删除闲置物品
     */
    @PreAuthorize("@ss.hasPermi('idle:idle:remove')")
    @Log(title = "闲置物品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idleIds}")
    public AjaxResult remove(@PathVariable Long[] idleIds)
    {
        return toAjax(idleService.deleteIdleByIdleIds(idleIds));
    }
}
